package com.jmgd.cjlx.controller;



import com.jmgd.cjlx.service.JmgdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/export")
public class ExcelExportController {
    @Autowired
    JmgdService jmgdService;


    /**
     *导出excel
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/lxExcel", method = RequestMethod.GET)
    public String lxExcel(String idNo) throws Exception {
       // System.out.println("11111111111111111111111");
        jmgdService.createExcelLx(idNo,null);
        return "success";
    }

    @RequestMapping(value = "/lxExcelAll", method = RequestMethod.GET)
    public String lxExcelAll() throws Exception {
        System.out.println("11111111111111111111111");
        jmgdService.createExcelLx(null,"1");
        return "success";
    }

    /*
    生成药监数据,批发销售出库，即系配送门店
    */
    @RequestMapping(value = "/lxExcelSaleYJ", method = RequestMethod.GET)
    public String lxExcelYJ(String beginDateStr,String endDateStr) throws Exception {
        System.out.println("生成药监批发配送开始");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println("============="+beginDateStr);
        System.out.println("============="+endDateStr);
        Date beginDate = sdf.parse(beginDateStr);
        Date endDate = sdf.parse(endDateStr);
        jmgdService.createExcelSaleYJ(beginDate,endDate);
        System.out.println("生成药监批发配送xml成功");
        return "success";
    }

    @RequestMapping(value = "/lxExcelSaleReturnYJ", method = RequestMethod.GET)
    public String lxExcelSaleReturnYJ(String beginDateStr,String endDateStr) throws Exception {
        System.out.println("生成药监批发配送退货开始");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println("============="+beginDateStr);
        System.out.println("============="+endDateStr);
        Date beginDate = sdf.parse(beginDateStr);
        Date endDate = sdf.parse(endDateStr);
        jmgdService.createExcelSaleReturnYJ(beginDate,endDate);
        System.out.println("生成药监批发配送退货xml成功");
        return "success";
    }

    @RequestMapping(value = "/lxExcelPurYJ", method = RequestMethod.GET)
    public String lxExcelPurYJ(String beginDateStr,String endDateStr) throws Exception {
        System.out.println("生成药监采购入库开始");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println("============="+beginDateStr);
        System.out.println("============="+endDateStr);
        Date beginDate = sdf.parse(beginDateStr);
        Date endDate = sdf.parse(endDateStr);
        jmgdService.createExcelPurYJ(beginDate,endDate);
        System.out.println("生成药监采购退货xml成功");
        return "success";
    }

    @RequestMapping(value = "/lxExcelPurReturnYJ", method = RequestMethod.GET)
    public String lxExcelPurReturnYJ(String beginDateStr,String endDateStr) throws Exception {
        System.out.println("生成药监采购退货开始");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println("============="+beginDateStr);
        System.out.println("============="+endDateStr);
        Date beginDate = sdf.parse(beginDateStr);
        Date endDate = sdf.parse(endDateStr);
        jmgdService.createExcelPurReturnYJ(beginDate,endDate);
        System.out.println("生成药监采购退货xml成功");
        return "success";
    }

    @RequestMapping(value = "/lxExcelStockYJ", method = RequestMethod.GET)
    public String lxExcelStockYJ(String beginDateStr,String endDateStr) throws Exception {
        System.out.println("生成药监仓库开始");
        System.out.println("============="+beginDateStr);
        System.out.println("============="+endDateStr);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date beginDate = sdf.parse(beginDateStr);
        jmgdService.createExcelStockYJ(beginDate);
        System.out.println("生成药监仓库xml生成");
        return "success";
    }



    @GetMapping("/ExcelOfSheet")
    public void ExcelOfSheet(HttpServletResponse response) {
        //准备各个sheet数据(这里为演示设置为空)
        List<String[]> dataQyxxList = new ArrayList<>();
        List<String[]> dataQyscxxList = new ArrayList<>();
        try {
            //数据1
            List<String[]> dataset1 = new ArrayList<String[]>();
            //for (int i = 0; i < dataQyxxList .size(); i++) {
                String[] arr1 = new String[2];//有几列就写几
                //如果数据不为空则赋值(这里就是循环每行的数据)
                arr1[0] = "111";
                arr1[1] = "222";
                dataset1.add(arr1);
            //}
            //数据2
            List<String[]> dataset2 = new ArrayList<String[]>();
         //   for (int i = 0; i < dataQyscxxList .size(); i++) {
                String[] arr2 = new String[2];//有几列就写几
                //如果数据不为空则赋值(这里就是循环每行的数据)
                arr2[0] = "111";
                arr2[1] = "222";
                dataset2.add(arr2);
            //}
            //设置sheet的表头与表名
            String[] handers1 = {"企业名称","统一社会信用代码"};
            String[] handers2 = {"机组名称","燃料类型"};


//            ExcelExp qyxxExp = new ExcelExp("企业信息", handers1,dataset1);
//            ExcelExp qyscxxExp = new ExcelExp("企业生产信息", handers2,dataset2);
//            List<ExcelExp> mysheet = new ArrayList<ExcelExp>();
//            mysheet.add(qyxxExp );
//            mysheet.add(qyscxxExp );
//            //fileName是你导出的文件名
//            String fileName = "企业信息";
//            //ExcelExportUtil是你设置Excel和下载控制的地方
//            ExcelExportUtil.exportManySheetExcel(fileName,mysheet,response); //生成sheet
        }catch (Exception e){

        }

    }
}

